package fr.paulmasson.jfreex.db.bo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;

@SuppressWarnings("serial")
@Entity
public class BoProvider extends Bo implements Serializable {

	

	private int id;
	private String name;
	private String channelUrl;
	private String channelUrlMirror;
	
	private List<BoChannel> channels = new ArrayList<BoChannel>();
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}
	
	

    @OneToMany(mappedBy="provider",cascade=CascadeType.ALL)
	public List<BoChannel> getChannels() {
		return this.channels;
	}
	
	public void setChannels(List<BoChannel> channels) {
		this.channels = channels;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getChannelUrl() {
		return channelUrl;
	}
	
	public void setChannelUrl(String channelUrl) {
		this.channelUrl = channelUrl;
	}
	
	public String getChannelUrlMirror() {
		return channelUrlMirror;
	}
	
	public void setChannelUrlMirror(String channelUrlMirror) {
		this.channelUrlMirror = channelUrlMirror;
	}
	
	public static String getTableName() {
		return "BoProvider";
	}

	public static String[] getColumns() {
		return new String[]{ "Id","Name","ChannelUrl","ChannelUrlMirror","Channels"}; 
	}

	private String toStringChannels() {
		StringBuffer res = new StringBuffer("[");
		if (null != channels) {
			for (int i=0; i<channels.size(); i++) {
				res.append(channels.get(i)+",");
			}
			res.replace(res.length()-1, res.length(), "]");
		} else {
			res.append("]");
		}
		return res.toString();
	}
	
	public String getColumnValue(Integer i) {
		switch(i) {
			case 0:
				return getId()+"";
			case 1:
				return getName();
			case 2:
				return getChannelUrl();
			case 3:
				return getChannelUrlMirror();
			case 4:
				return toStringChannels();
		}
		return null;
	}
	
	public String toString() {
		return this.getId()+":"+this.getName();
	}
	
}
